package com.gary.spring.proxy;

import com.gary.spring.scope.E;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @author peng_rui
 * @date 2022/7/3
 */
public class JdkProxyDeep {

    interface InvocationHandler {
        Object invoke($JdkProxy0 proxy0, Method method, Object[] params) throws Throwable;
    }

    interface Foo {
        void foo();

        Integer bra();
    }

    static class Target implements Foo {

        @Override
        public void foo() {
            System.out.println("target foo ...");
        }

        @Override
        public Integer bra() {
            System.out.println("target bra ...");
            return 1;
        }
    }

    public static void main(String[] args) throws Exception {
        Target target = new Target();
        $JdkProxy0 proxy0 = new $JdkProxy0(new InvocationHandler() {
            @Override
            public Object invoke($JdkProxy0 proxy0, Method method, Object[] params) throws Throwable {
                System.out.println("proxy0 : " + proxy0);
                System.out.println("before...");
                Object invoke = method.invoke(target, null);
                return invoke;

            }
        });
        proxy0.foo();
        Integer bra = proxy0.bra();
        System.out.println("bra : " + bra);

        System.in.read();
    }
}
